package com.tuiyun.jxgl.action;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.transaction.annotation.Transactional;

import com.tuiyun.jxgl.bean.Student;
import com.tuiyun.jxgl.dao.StudentHome;

public class ShowMeAction {
	private Student student;
	private StudentHome sh;
	public StudentHome getSh() {
		return sh;
	}

	public void setSh(StudentHome sh) {
		this.sh = sh;
	}
	private int id = -1;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}
	@Transactional
	public String execute(){
		if(id != -1){
			//admin sees student
			Student s = sh.findById(id);
            setStudent(s);
		}else{
			//student edit itself
			Subject subject = SecurityUtils.getSubject();		
	        if (subject != null) {        	
	            Student s = (Student) subject.getPrincipal();	            
	            setStudent(s);
	        }
		}
		return "success";
	}
}
